package org.demo.filemanager.widget.xml;

import java.util.ArrayList;
import java.util.List;

import org.boxlayout.gui.BoxLayoutEngine;
import org.boxlayout.gui.widget.AbstractOnDemandTreeBrowsableWidget;
import org.boxlayout.gui.widget.TreeBrowsable;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public abstract class AbstractXmlWidget extends AbstractOnDemandTreeBrowsableWidget {

	Node node;
	Boolean childInited = false;
	
	public AbstractXmlWidget(BoxLayoutEngine ble,Node node){
		super(ble);
		name = node.getNodeName();
		this.node = node;
	}
	

	
	void initChilds(){
		childs = new ArrayList<TreeBrowsable>();
		NodeList xmlChilds = node.getChildNodes();

		for(Integer i =0,n=xmlChilds.getLength();i<n;i++){
			TreeBrowsable child = XmlWidgetFactory.getInstance().createXmlWidget(ble,xmlChilds.item(i));
			if(child!=null){
				child.initVisual().setParent(this);
				childs.add(child);
			}
		}
		childInited = true;
	}
	
	public List<TreeBrowsable> getChilds(){
		if(!childInited){
			initChilds();
		}
		return childs;
	}
	
	
	
	
	
}
